<template>
    <div class=" zy-content ">
<!--        <div class="search clear">-->
<!--            <Tabs type="card" @on-click="handleChangeTab" :value="tagName">-->
<!--                <TabPane label="异动申请" name="1" >-->
<!--                    <apply-list :factoryList="factoryList" :orgList="orgList" :applyDataSource="dataSource" :dataTotal="dataTotal" />-->
<!--                </TabPane>-->
<!--                <TabPane label="异动审批" name="2">-->
<!--                    <approve-list :factoryList="factoryList" :orgList="orgList" :approveDataSource="approveDataSource" :approveTotal="approveTotal"/>-->
<!--                </TabPane>-->
<!--                <TabPane label="实物异动" name="3" >-->
<!--                    <changes-list :factoryList="factoryList" :orgList="orgList" :matterDataSource="matterDataSource" :matterTotal="matterTotal"/>-->
<!--                </TabPane>-->
<!--                <TabPane label="台账更新" name="4">-->
<!--                    <update-list :deviceMId="deviceMId" :factoryList="factoryList" :orgList="orgList" :stageDataSource="stageDataSource" :stageTotal="stageTotal"/>-->
<!--                </TabPane>-->
<!--            </Tabs>-->
          <!-- 我的申请 -->
          <apply-list v-if="nameStr === 'myapplication'" :factoryList="factoryList" :orgList="orgList" :applyDataSource="dataSource" :dataTotal="dataTotal" />
         <!-- 实物异动 -->
         <changes-list v-if="nameStr === 'physicalchanges'" :factoryList="factoryList" :orgList="orgList" :matterDataSource="matterDataSource" :matterTotal="matterTotal"/>
<!--        </div>-->
    </div>
</template>

<script>
    import recursion from '../../../util/recursion'
import applyList from './modules/applyList'
    // import approveList from './modules/approveList'
    import changesList from './modules/changesList'
    // import updateList from './modules/updateList'

    export default {
        name: "equipmentsChangesList",
        components: {
            applyList,
            // approveList,
            changesList,
            // updateList
        },
        data() {
            return {
                dataTotal: 0,
                approveTotal: 0,
                matterTotal: 0,
                stageTotal: 0,
                tagName: '3',
                factoryList: [],//工厂数据
                orgList: [],//区域级联数据
                dataSource: [],
                approveDataSource: [],
                matterDataSource: [],
                stageDataSource: [],
                deviceMId: 'myapplication',
                nameStr:this.$route.params.tagName
            }
        },
        created() {
          this.nameStr = this.$route.params.tagName
          switch (this.nameStr) {
            case 'myapplication':
               this.handleChangeTab(1)
                  break;
            case 'physicalchanges':
              this.handleChangeTab(3)
              break;
          }
            this.deviceMId = this.$route.query.deviceMId
            if (this.deviceMId) {
                this.tagName = '4'
            }
            this.getCompanyList()
            this.getOrgList()
        },
    watch: {
        '$route'(to, from) {
            this.nameStr =to.params.tagName
            switch (to.params.tagName) {
                case 'myapplication':
                    this.handleChangeTab(1)
                    break;
                case 'physicalchanges':
                    this.handleChangeTab(3)
                    break;
            }
        }
    },
        methods: {
            /**************获取相关下拉数据列表*************/
            getCompanyList() {
                this.axios({
                    method: 'get',
                    url: '/basic/company/getCompanyListByUser',
                    params: {}
                }).then(res => {
                    if (res.code === 200) {
                        let arr = res.data.map(item => {
                            return {
                                ...item,
                                id: item.id.toString()
                            }
                        })
                        this.factoryList = arr
                    } else {
                        this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                    }
                })
            },
            
            getOrgList() {
                this.axios({
                    method: 'get',
                    url: '/basic/organization/findListByToken',
                    params: {}
                }).then(res => {
                    if (res.code === 200) {
                        const obj = {
                            label: 'name',
                            value: 'id',
                            children: 'children'
                        }
                        this.orgList = recursion.convertTree(res.data, obj)
                    } else {
                        this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                    }
                })
            },
            /******************列表按钮操作**********************/
            handleChangeTab(name) {
                console.log(name)
                this.tagName = name
                if (name == 1) {
                    let params = {
                        pageNum: 1,
                        pageSize: 10,
                    };
                    this.axios({
                        method: 'get',
                        url: '/dms/dmsMoveApply/getDeviceMoveList',
                        params: params
                    }).then(res => {
                        
                        if (res.code === 200) {
                            this.dataSource = res.data.list
                            this.dataTotal = res.data.total
                        } else {
                            this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                        }
                    })
                }else if (name == 2) {
                    let params = {
                        pageNum: 1,
                        pageSize: 10,
                    };
                    this.axios({
                        method: 'get',
                        url: '/dms/dmsMoveApply/getDeviceMoveSpList',
                        params: params
                    }).then(res => {
                        
                        if (res.code === 200) {
                            this.approveDataSource = res.data.list
                            this.approveTotal = res.data.total
                        } else {
                            this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                        }
                    })
                }else if (name == 3) {
                    let params = {
                        pageNum: 1,
                        pageSize: 10,
                    };
                    this.axios({
                        method: 'get',
                        url: '/dms/dmsMoveApply/getDeviceSwMoveSpList',
                        params: params
                    }).then(res => {
                        
                        if (res.code === 200) {
                            this.matterDataSource = res.data.list
                            this.matterTotal = res.data.total
                        } else {
                            this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                        }
                    })
                }else {
                    let params = {
                        pageNum: 1,
                        pageSize: 10,
                    };
                    if (this.deviceMId) {
                        this.$set(params, 'deviceMId', this.deviceMId)
                    }
                    this.axios({
                        method: 'get',
                        url: '/dms/dmsMoveApply/getDeviceTzMoveSpList',
                        params: params
                    }).then(res => {
                        
                        if (res.code === 200) {
                            this.stageDataSource = res.data.list
                            this.stageTotal = res.data.total
                        } else {
                            this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                        }
                    })
                }
            },
            // //批量导入
            // handleBatchImport() {
            //     console.log('123')
            //     this.$refs.ledgerImportExcel.show()
            //
            // },
            //
            // //批量操作
            // handleSelectionChange() {
            //
            // },
            // handleRefresh() {
            //     this.searchList()
            // },
            //分页
            // changeNum() {
            //     this.pageNum = 1;
            //     this.searchList();
            // },
            // changePageSize(pageSize) {
            //     this.pageSize = pageSize;
            //     this.searchList();
            // },
            // changePageNum(val) {
            //     this.pageNum = val;
            //     this.searchList();
            // },
            // searchList() {
            //     let params = {
            //         companyId: this.tagName,
            //         pageNum: this.pageNum,
            //         pageSize: this.pageSize,
            //     };
            //     for (let key in this.searchParams) {
            //         if (key === 'orgId' && this.searchParams['orgId']) {
            //             const arr = this.searchParams[key]
            //             const {length, last = length - 1} = arr
            //             this.$set(params, key, arr[last])
            //         } else {
            //             if (this.searchParams[key]) {
            //                 this.$set(params, key, this.searchParams[key])
            //             }
            //         }
            //
            //     }
            //     this.axios({
            //         method: 'get',
            //         url: '/dms/dmsMoveApply/getDeviceMoveList',
            //         params: params
            //     }).then(res => {
            //         
            //         if (res.code === 200) {
            //             this.dataSource = res.data.list
            //             this.total = res.data.total
            //         } else {
            //             this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
            //         }
            //     })
            // },
            //详情页
            // handleDetail(row) {
            //     this.$refs.addChangesModal.show('detail', row, true)
            // },
            // handlePrint(record) {
            //     this.$refs.ledgerPrintModal.show(record)
            // },
        }
    }
</script>

<style scoped lang="scss">
    .equipmentDataManagement {
        .ivu-tabs.ivu-tabs-card {
            .ivu-tabs-tab {
                width: 120px !important;
                text-align: center;
            }
            ::v-deep.ivu-tabs-tab.ivu-tabs-tab-active {
                color: #ffffff;
                background-color: #2d8cf0;
            }
        }
    }
</style>
